<!DOCTYPE html>
<html class="no-js" lang="zh_CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">

    <title>${system_admin_title}</title>
    #required_css
</head>

<body>
<div class="app $!layout">
    <!-- 头部菜单 -->
    <section class="layout">
        <!-- 菜单 -->
        <section class="container">
            <!-- 内容主体 -->
            <section class="main-content">
                <!-- 主体操作栏 -->
                <header class="header navbar">
                    <!-- 左按钮区 -->
                    <div class="btn-group tool-button">
                        #ifAuthButton("btnAdd")
                        <a class="btn btn-primary navbar-btn" onclick="doAdd()"><i class="fa fa-user-plus"></i> 新增按钮</a>
                        #end
                    </div>
                    <div class="pull-right offscreen-right">
                    </div>
                </header>
                <div class="content-wrap">
                    <div class="wrapper">
                        <div class="row">
                            <div class="col-lg-12 col-md-12">
                                <table id="dgButton"></table>
                                <div id="dgButtonPager"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <a class="exit-offscreen"></a>
            </section>
        </section>
    </section>
</div>
#required_js
<script type="text/javascript">
    ns.requireJS("/framework/js/view/datagrid.js");
    var dgButton;
    ns.ready(function(){
        dgButton = $("#dgButton").jqGrid({
            url: '$!basePath/system/button/data',
            colModel: [
                { label: 'ID', name: 'id', key: true, hidden:true },
                { label: '名称', name: 'name', width:100},
                { label: 'Code', name: 'code', width:100},
                { label: '是否启用', name: 'enabled', width:30, formatter:function(val){
                    return ns.view.datagrid.renderEnabled(val);
                }},
                { label:'描述', name: 'descript' },
                { label:'操作',formatter:function(val,node,data){
                    return ns.view.datagrid.renderOp([
                        {title:"编辑", onclick:function(){
                            ns.view.showModal("$!basePath/system/button/edit/"+data.id,{
                                onHidden : function(dialog, obj){
                                    if(dialog.isEdited){
                                        dgButton.reload();
                                    }
                                }
                            });
                        }},
                        {title:"删除", onclick:function(){
                            doDelete(data.id);
                        }}
                    ]);
                } }
            ],
            rownumbers:true,
            height: $(".wrapper").height() - 80,
            pager: "#dgButtonPager"
        });
    });
    function doAdd(){
        ns.view.showModal("$!basePath/system/button/add",{
            onHidden : function(dialog, obj){
                if(dialog.isSaved){
                    dgButton.reload();
                }
            }
        });
    }
    function doDelete(id){
        ns.tip.confirm("确定要删除此按钮吗？", function(){
           ns.get("$!basePath/system/button/delete/"+id,function(success, data){
              if(success){
                  dgButton.reload();
              } else{
                  ns.tip.toast.error(data.error);
              }
           });
        });
    }
</script>
</body>
</html>
